package com.bzframework.pro.api.core.mock;

import com.bzframework.pro.api.core.model.DemoCode;
import com.bzframework.pro.api.core.model.OpenApiHeader;
import com.bzframework.pro.api.core.model.ParameterType;
import com.bzframework.pro.api.core.provider.ApiSupport;
import com.bzframework.pro.api.core.provider.ApiSupportProvider;
import com.bzframework.pro.api.core.provider.CompositeApiSupport;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import reactor.core.publisher.Flux;

import java.util.Collections;

/**
 * @Author bingzhong
 * @Date 2025/2/25 18:03
 * @Description
 */
public class MockApiProvider implements ApiSupportProvider {

    @Override
    public Flux<ApiSupport> create() {
        CompositeApiSupport mockApiSupport1 = new CompositeApiSupport();
        mockApiSupport1.setId("mock-api11111111111111111111111111");
        mockApiSupport1.setName("mock-api111111111111111111111111");
        mockApiSupport1.setUrl("http://www.baidu.com");
        mockApiSupport1.setMethod(HttpMethod.GET);
        mockApiSupport1.setDemoUrl("http://www.baidu.com/asdfasdfasfasfsafsadfafa");
        mockApiSupport1.setResponseType(MediaType.APPLICATION_JSON_VALUE);
        mockApiSupport1.setDescription("你好呀！测试接口1");
        OpenApiHeader openApiHeader = new OpenApiHeader();
        openApiHeader.setName("Authorization");
        openApiHeader.setValue("1234");
        openApiHeader.setType(ParameterType.string);
        openApiHeader.setRequired(true);
        openApiHeader.setDescription("请求鉴权字段");
        mockApiSupport1.setHeaders(Collections.singletonList(openApiHeader));
        mockApiSupport1.setQueryParams(null);
        mockApiSupport1.setResponseDemo("{\"code\":200,\"msg\":\"success\",\"data\":\"hello world\"}");
        mockApiSupport1.setDemoCodes(Collections.singletonList(DemoCode.of("Python", "import requests\n\nresponse = requests.get('http://www.baidu.com')\nprint(response.text)")));

        CompositeApiSupport mockApiSupport2 = new CompositeApiSupport();
        mockApiSupport2.setId("mock-api222222222222222222222222222222");
        mockApiSupport2.setName("mock-api22222222222222222222222222");
        mockApiSupport2.setUrl("http://www.baidu.com");
        mockApiSupport2.setMethod(HttpMethod.GET);
        mockApiSupport2.setDemoUrl("");
        mockApiSupport2.setResponseType(MediaType.APPLICATION_JSON_VALUE);
        mockApiSupport2.setDescription("你好呀！测试接口2");
        OpenApiHeader openApiHeader2 = new OpenApiHeader();
        openApiHeader2.setName("Authorization");
        openApiHeader2.setValue("1234");
        openApiHeader2.setType(ParameterType.string);
        openApiHeader2.setRequired(true);
        openApiHeader2.setDescription("");
        mockApiSupport2.setHeaders(Collections.singletonList(openApiHeader2));
        mockApiSupport2.setQueryParams(null);

        return Flux.just(mockApiSupport1, mockApiSupport2);
    }
}
